package com.example.myapplication.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.example.myapplication.R
import com.example.myapplication.adapter.QuickAdapter
import com.example.myapplication.bean.AdapterDataBean
import kotlinx.android.synthetic.main.fragment_quick_adapter.*

class QuickFragment: Fragment() {
    var adapter:QuickAdapter? = null;
    var data:MutableList<AdapterDataBean> = ArrayList()
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        var view =inflater.inflate(R.layout.fragment_quick_adapter,container,false)
        return view
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
        initData()
    }

    private fun initData() {
        data.add(AdapterDataBean("aa1","aa2"))
        data.add(AdapterDataBean("bb1","bb2"))
        data.add(AdapterDataBean("cc1","cc2"))
        data.add(AdapterDataBean("dd1","dd2"))
        data.add(AdapterDataBean("ee1","ee2"))

    }

    private fun initView() {
        title.text="QuickFragment"
        var layoutManager = LinearLayoutManager(activity)
        adapter = QuickAdapter(R.layout.adapter_item1,data)
        adapter?.setOnItemChildClickListener(BaseQuickAdapter.OnItemChildClickListener {
            adapter, view, position ->
            when(view.id){
                R.id.text1->Toast.makeText(activity,"aaa",Toast.LENGTH_LONG).show()
                R.id.text2->Toast.makeText(activity,"bbb",Toast.LENGTH_LONG).show()
            }
        })
        recycle_view.layoutManager=layoutManager
        recycle_view.adapter = adapter

    }
}